﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using cebao.DBUtility;//Please add references
namespace cebao.DAL
{
	/// <summary>
	/// 数据访问类:ForestPets
	/// </summary>
	public partial class ForestPets
	{
		public ForestPets()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("fp_id", "ForestPets"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int fp_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from ForestPets");
			strSql.Append(" where fp_id=@fp_id");
			SqlParameter[] parameters = {
					new SqlParameter("@fp_id", SqlDbType.Int,4)
			};
			parameters[0].Value = fp_id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(cebao.Model.ForestPets model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ForestPets(");
			strSql.Append("address,inputTime,petsName,petsId,plantsName,plantsId,investigationMethod,standardnumber,petStage,eggParts,damageParts,totalUnit,larvaAge,monitorWay,toolsNums,femaleNums,maleNums,pupaParts,havePupa,haveEgg,petsDensity,uid,happenpro)");
			strSql.Append(" values (");
			strSql.Append("@address,@inputTime,@petsName,@petsId,@plantsName,@plantsId,@investigationMethod,@standardnumber,@petStage,@eggParts,@damageParts,@totalUnit,@larvaAge,@monitorWay,@toolsNums,@femaleNums,@maleNums,@pupaParts,@havePupa,@haveEgg,@petsDensity,@uid,@happenpro)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@address", SqlDbType.VarChar,50),
					new SqlParameter("@inputTime", SqlDbType.DateTime),
					new SqlParameter("@petsName", SqlDbType.VarChar,50),
					new SqlParameter("@petsId", SqlDbType.Int,4),
					new SqlParameter("@plantsName", SqlDbType.VarChar,50),
					new SqlParameter("@plantsId", SqlDbType.Int,4),
					new SqlParameter("@investigationMethod", SqlDbType.VarChar,50),
					new SqlParameter("@standardnumber", SqlDbType.VarChar,50),
					new SqlParameter("@petStage", SqlDbType.VarChar,50),
					new SqlParameter("@eggParts", SqlDbType.VarChar,50),
					new SqlParameter("@damageParts", SqlDbType.VarChar,50),
					new SqlParameter("@totalUnit", SqlDbType.VarChar,50),
					new SqlParameter("@larvaAge", SqlDbType.VarChar,50),
					new SqlParameter("@monitorWay", SqlDbType.VarChar,50),
					new SqlParameter("@toolsNums", SqlDbType.VarChar,50),
					new SqlParameter("@femaleNums", SqlDbType.VarChar,50),
					new SqlParameter("@maleNums", SqlDbType.VarChar,50),
					new SqlParameter("@pupaParts", SqlDbType.VarChar,50),
					new SqlParameter("@havePupa", SqlDbType.VarChar,50),
					new SqlParameter("@haveEgg", SqlDbType.VarChar,50),
					new SqlParameter("@petsDensity", SqlDbType.VarChar,50),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@happenpro", SqlDbType.VarChar,50)};
			parameters[0].Value = model.address;
			parameters[1].Value = model.inputTime;
			parameters[2].Value = model.petsName;
			parameters[3].Value = model.petsId;
			parameters[4].Value = model.plantsName;
			parameters[5].Value = model.plantsId;
			parameters[6].Value = model.investigationMethod;
			parameters[7].Value = model.standardnumber;
			parameters[8].Value = model.petStage;
			parameters[9].Value = model.eggParts;
			parameters[10].Value = model.damageParts;
			parameters[11].Value = model.totalUnit;
			parameters[12].Value = model.larvaAge;
			parameters[13].Value = model.monitorWay;
			parameters[14].Value = model.toolsNums;
			parameters[15].Value = model.femaleNums;
			parameters[16].Value = model.maleNums;
			parameters[17].Value = model.pupaParts;
			parameters[18].Value = model.havePupa;
			parameters[19].Value = model.haveEgg;
			parameters[20].Value = model.petsDensity;
			parameters[21].Value = model.uid;
			parameters[22].Value = model.happenpro;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(cebao.Model.ForestPets model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ForestPets set ");
			strSql.Append("address=@address,");
			strSql.Append("inputTime=@inputTime,");
			strSql.Append("petsName=@petsName,");
			strSql.Append("petsId=@petsId,");
			strSql.Append("plantsName=@plantsName,");
			strSql.Append("plantsId=@plantsId,");
			strSql.Append("investigationMethod=@investigationMethod,");
			strSql.Append("standardnumber=@standardnumber,");
			strSql.Append("petStage=@petStage,");
			strSql.Append("eggParts=@eggParts,");
			strSql.Append("damageParts=@damageParts,");
			strSql.Append("totalUnit=@totalUnit,");
			strSql.Append("larvaAge=@larvaAge,");
			strSql.Append("monitorWay=@monitorWay,");
			strSql.Append("toolsNums=@toolsNums,");
			strSql.Append("femaleNums=@femaleNums,");
			strSql.Append("maleNums=@maleNums,");
			strSql.Append("pupaParts=@pupaParts,");
			strSql.Append("havePupa=@havePupa,");
			strSql.Append("haveEgg=@haveEgg,");
			strSql.Append("petsDensity=@petsDensity,");
			strSql.Append("uid=@uid,");
			strSql.Append("happenpro=@happenpro");
			strSql.Append(" where fp_id=@fp_id");
			SqlParameter[] parameters = {
					new SqlParameter("@address", SqlDbType.VarChar,50),
					new SqlParameter("@inputTime", SqlDbType.DateTime),
					new SqlParameter("@petsName", SqlDbType.VarChar,50),
					new SqlParameter("@petsId", SqlDbType.Int,4),
					new SqlParameter("@plantsName", SqlDbType.VarChar,50),
					new SqlParameter("@plantsId", SqlDbType.Int,4),
					new SqlParameter("@investigationMethod", SqlDbType.VarChar,50),
					new SqlParameter("@standardnumber", SqlDbType.VarChar,50),
					new SqlParameter("@petStage", SqlDbType.VarChar,50),
					new SqlParameter("@eggParts", SqlDbType.VarChar,50),
					new SqlParameter("@damageParts", SqlDbType.VarChar,50),
					new SqlParameter("@totalUnit", SqlDbType.VarChar,50),
					new SqlParameter("@larvaAge", SqlDbType.VarChar,50),
					new SqlParameter("@monitorWay", SqlDbType.VarChar,50),
					new SqlParameter("@toolsNums", SqlDbType.VarChar,50),
					new SqlParameter("@femaleNums", SqlDbType.VarChar,50),
					new SqlParameter("@maleNums", SqlDbType.VarChar,50),
					new SqlParameter("@pupaParts", SqlDbType.VarChar,50),
					new SqlParameter("@havePupa", SqlDbType.VarChar,50),
					new SqlParameter("@haveEgg", SqlDbType.VarChar,50),
					new SqlParameter("@petsDensity", SqlDbType.VarChar,50),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@happenpro", SqlDbType.VarChar,50),
					new SqlParameter("@fp_id", SqlDbType.Int,4)};
			parameters[0].Value = model.address;
			parameters[1].Value = model.inputTime;
			parameters[2].Value = model.petsName;
			parameters[3].Value = model.petsId;
			parameters[4].Value = model.plantsName;
			parameters[5].Value = model.plantsId;
			parameters[6].Value = model.investigationMethod;
			parameters[7].Value = model.standardnumber;
			parameters[8].Value = model.petStage;
			parameters[9].Value = model.eggParts;
			parameters[10].Value = model.damageParts;
			parameters[11].Value = model.totalUnit;
			parameters[12].Value = model.larvaAge;
			parameters[13].Value = model.monitorWay;
			parameters[14].Value = model.toolsNums;
			parameters[15].Value = model.femaleNums;
			parameters[16].Value = model.maleNums;
			parameters[17].Value = model.pupaParts;
			parameters[18].Value = model.havePupa;
			parameters[19].Value = model.haveEgg;
			parameters[20].Value = model.petsDensity;
			parameters[21].Value = model.uid;
			parameters[22].Value = model.happenpro;
			parameters[23].Value = model.fp_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int fp_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ForestPets ");
			strSql.Append(" where fp_id=@fp_id");
			SqlParameter[] parameters = {
					new SqlParameter("@fp_id", SqlDbType.Int,4)
			};
			parameters[0].Value = fp_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string fp_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ForestPets ");
			strSql.Append(" where fp_id in ("+fp_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public cebao.Model.ForestPets GetModel(int fp_id)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 fp_id,address,inputTime,petsName,petsId,plantsName,plantsId,investigationMethod,standardnumber,petStage,eggParts,damageParts,totalUnit,larvaAge,monitorWay,toolsNums,femaleNums,maleNums,pupaParts,havePupa,haveEgg,petsDensity,uid,happenpro,totalCount from ForestPets ");
			strSql.Append(" where fp_id=@fp_id");
			SqlParameter[] parameters = {
					new SqlParameter("@fp_id", SqlDbType.Int,4)
			};
			parameters[0].Value = fp_id;

			cebao.Model.ForestPets model=new cebao.Model.ForestPets();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public cebao.Model.ForestPets DataRowToModel(DataRow row)
		{
			cebao.Model.ForestPets model=new cebao.Model.ForestPets();
			if (row != null)
			{
				if(row["fp_id"]!=null && row["fp_id"].ToString()!="")
				{
					model.fp_id=int.Parse(row["fp_id"].ToString());
				}
				if(row["address"]!=null)
				{
					model.address=row["address"].ToString();
				}
				if(row["inputTime"]!=null && row["inputTime"].ToString()!="")
				{
					model.inputTime=DateTime.Parse(row["inputTime"].ToString());
				}
				if(row["petsName"]!=null)
				{
					model.petsName=row["petsName"].ToString();
				}
				if(row["petsId"]!=null && row["petsId"].ToString()!="")
				{
					model.petsId=int.Parse(row["petsId"].ToString());
				}
				if(row["plantsName"]!=null)
				{
					model.plantsName=row["plantsName"].ToString();
				}
				if(row["plantsId"]!=null && row["plantsId"].ToString()!="")
				{
					model.plantsId=int.Parse(row["plantsId"].ToString());
				}
				if(row["investigationMethod"]!=null)
				{
					model.investigationMethod=row["investigationMethod"].ToString();
				}
				if(row["standardnumber"]!=null)
				{
					model.standardnumber=row["standardnumber"].ToString();
				}
				if(row["petStage"]!=null)
				{
					model.petStage=row["petStage"].ToString();
				}
				if(row["eggParts"]!=null)
				{
					model.eggParts=row["eggParts"].ToString();
				}
				if(row["damageParts"]!=null)
				{
					model.damageParts=row["damageParts"].ToString();
				}
				if(row["totalUnit"]!=null)
				{
					model.totalUnit=row["totalUnit"].ToString();
				}
				if(row["larvaAge"]!=null)
				{
					model.larvaAge=row["larvaAge"].ToString();
				}
				if(row["monitorWay"]!=null)
				{
					model.monitorWay=row["monitorWay"].ToString();
				}
				if(row["toolsNums"]!=null)
				{
					model.toolsNums=row["toolsNums"].ToString();
				}
				if(row["femaleNums"]!=null)
				{
					model.femaleNums=row["femaleNums"].ToString();
				}
				if(row["maleNums"]!=null)
				{
					model.maleNums=row["maleNums"].ToString();
				}
				if(row["pupaParts"]!=null)
				{
					model.pupaParts=row["pupaParts"].ToString();
				}
				if(row["havePupa"]!=null)
				{
					model.havePupa=row["havePupa"].ToString();
				}
				if(row["haveEgg"]!=null)
				{
					model.haveEgg=row["haveEgg"].ToString();
				}
				if(row["petsDensity"]!=null)
				{
					model.petsDensity=row["petsDensity"].ToString();
				}
				if(row["uid"]!=null && row["uid"].ToString()!="")
				{
					model.uid=int.Parse(row["uid"].ToString());
				}
				if(row["happenpro"]!=null)
				{
					model.happenpro=row["happenpro"].ToString();
				}
                if (row["totalCount"] != null)
                {
                    model.totalCount = row["totalCount"].ToString();
                }
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select fp_id,address,inputTime,petsName,petsId,plantsName,plantsId,investigationMethod,standardnumber,petStage,eggParts,damageParts,totalUnit,larvaAge,monitorWay,toolsNums,femaleNums,maleNums,pupaParts,havePupa,haveEgg,petsDensity,uid,happenpro ");
			strSql.Append(" FROM ForestPets ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" fp_id,address,inputTime,petsName,petsId,plantsName,plantsId,investigationMethod,standardnumber,petStage,eggParts,damageParts,totalUnit,larvaAge,monitorWay,toolsNums,femaleNums,maleNums,pupaParts,havePupa,haveEgg,petsDensity,uid,happenpro ");
			strSql.Append(" FROM ForestPets ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}
        public DataSet GetListdis(int uid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT distinct mhid, hname FROM  VForestPets WHERE uid="+uid);
            return DbHelperSQL.Query(strSql.ToString());
        }
		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM VForestPets ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
        public int GetRecordCountc(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM (select convert(varchar(10),inputTime,120) as inputTime,[address],[hname],[pname],[uname],[uid],[mname] from VForestPets where petStage='成虫'  ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere);
            }
            strSql.Append("group by convert(varchar(10),inputTime,120),[address],[hname],[pname],[uname],[uid],[mname]) T");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        public int GetRecordCountcollect(string strWhere,string type)
        {
            StringBuilder strSql = new StringBuilder();
            if (type == "d")
            {
                strSql.Append("select count(*) from ( SELECT hname FROM (select * FROM VForestPets ");
                if (strWhere.Trim() != "")
                {
                    strSql.Append(" where " + strWhere);
                }
                strSql.Append(") a group by hname,convert(varchar(10),[inputTime],120)) mt ");
            }
            else if (type == "m")
            {
                strSql.Append("select count(*) from ( SELECT hname FROM (select * FROM VForestPets ");
                if (strWhere.Trim() != "")
                {
                    strSql.Append(" where " + strWhere);
                }
                strSql.Append(") a group by hname,convert(varchar(7),[inputTime],120)) mt ");

            }
            else if (type == "x")
            {                
                strSql.Append("select count(*) from (SELECT  convert(varchar(7),[inputTime],120)+'-01' as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets where day(inputTime)<=10");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" and " + strWhere);
                }
                strSql.Append(") y group by hname,convert(varchar(7),[inputTime],120) ");
                strSql.Append(" union SELECT  convert(varchar(7),[inputTime],120)+'-11' as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets where day(inputTime)>10 and day(inputTime)<=20");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" and " + strWhere);
                }
                strSql.Append(") y group by hname,convert(varchar(7),[inputTime],120) ");
                strSql.Append(" union SELECT  convert(varchar(7),[inputTime],120)+'-21' as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets where day(inputTime)>20");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" and " + strWhere);
                }
                strSql.Append(" ) y group by hname,convert(varchar(7),[inputTime],120) ");
                strSql.Append(") mt ");

            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        public DataSet GetListByPagec(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.fp_id desc");
            }
            strSql.Append(")AS Row, T.*  from (select convert(varchar(10),inputTime,120) as inputTime,[address],[hname],[pname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums,[uname],[uid],[mname] from VForestPets where petStage='成虫' ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" and " + strWhere);
            }
            strSql.Append("group by convert(varchar(10),inputTime,120),[address],[hname],[pname],[uname],[uid],[mname]) T ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.fp_id desc");
			}
			strSql.Append(")AS Row, T.*  from VForestPets T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}
        public DataSet GetListCollectexcel(string strWhere)//成虫汇总信息
        {
            StringBuilder strSql = new StringBuilder();
                        
                strSql.Append("SELECT  convert(varchar(10),[inputTime],120) as inputTime,[hname],sum(cast([femaleNums] as int))+sum(cast([maleNums] as int)) as  allsum FROM (select * from Vforestpets");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" WHERE " + strWhere);
                }
                strSql.Append(") mt group by hname,convert(varchar(10),[inputTime],120) order by hname,inputTime");               
                       
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetListCollect(string strWhere, string orderby, int startIndex, int endIndex,string type)//成虫汇总信息
        {
            StringBuilder strSql = new StringBuilder();
            if (type == "d")
            {
                strSql.Append("SELECT * FROM ( ");
                strSql.Append(" SELECT ROW_NUMBER() OVER (");
                if (!string.IsNullOrEmpty(orderby.Trim()))
                {
                    strSql.Append("order by T." + orderby);
                }
                else
                {
                    strSql.Append("order by T.inputTime desc");
                }
                strSql.Append(")AS Row, T.*  from (SELECT  convert(varchar(10),[inputTime],120) as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" WHERE " + strWhere);
                }
                strSql.Append(") mt group by hname,convert(varchar(10),[inputTime],120))  T ) TT");
                strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            }
            else if (type == "m")
            {
                strSql.Append("SELECT * FROM ( ");
                strSql.Append(" SELECT ROW_NUMBER() OVER (");
                if (!string.IsNullOrEmpty(orderby.Trim()))
                {
                    strSql.Append("order by T." + orderby);
                }
                else
                {
                    strSql.Append("order by T.inputTime desc");
                }
                strSql.Append(")AS Row, T.*  from (SELECT  convert(varchar(7),[inputTime],120)+'-01' as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" WHERE " + strWhere);
                }
                strSql.Append(") mt group by hname,convert(varchar(7),[inputTime],120))  T ) TT");
                strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);

            }
            else if (type == "x")
            {
                strSql.Append("SELECT * FROM ( ");
                strSql.Append(" SELECT ROW_NUMBER() OVER (");
                if (!string.IsNullOrEmpty(orderby.Trim()))
                {
                    strSql.Append("order by T." + orderby);
                }
                else
                {
                    strSql.Append("order by T.inputTime desc");
                }
                strSql.Append(")AS Row, T.*  from (SELECT  convert(varchar(7),[inputTime],120)+'-01' as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets where day(inputTime)<=10");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" and " + strWhere);
                }
                strSql.Append(") y group by hname,convert(varchar(7),[inputTime],120) ");
                strSql.Append(" union SELECT  convert(varchar(7),[inputTime],120)+'-11' as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets where day(inputTime)>10 and day(inputTime)<=20");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" and " + strWhere);
                }
                strSql.Append(") y group by hname,convert(varchar(7),[inputTime],120) ");
                strSql.Append(" union SELECT  convert(varchar(7),[inputTime],120)+'-21' as inputTime,[hname],sum(cast([femaleNums] as int)) as femaleNums,sum(cast([maleNums] as int)) as maleNums FROM (select * from Vforestpets where day(inputTime)>20");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" and " + strWhere);
                }
                strSql.Append(") y group by hname,convert(varchar(7),[inputTime],120) ");
                strSql.Append(") T ) TT");
                strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);

            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetListca(string abh, string harm, string stime, string etime, string ptype, string mlevel)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select hname,[Stage],[totalUnit],SUM(cast(l as decimal(18,2))) as l,SUM(cast(c as decimal(18,2))) as c,SUM(cast(h as decimal(18,2))) as h from Vallharmful where 1=1");
            if (harm != "")
                strSql.AppendFormat(" and hname='{0}'", harm);
            if (stime != "")
                strSql.AppendFormat(" and inputTime>='{0}'", stime);
            if (etime != "")
                strSql.AppendFormat(" and inputTime<='{0}'", etime);
            if (ptype != "")
            {
                strSql.AppendFormat(" and ptype='{0}'", ptype);

            }
            if (mlevel != "" && mlevel != "4,3,2,1")
                strSql.AppendFormat(" and mlevel in ({0})", mlevel);
            if (abh.Length == 6)
            {
                if (abh.EndsWith("000000"))
                    strSql.Append(" group by hname,[Stage],[totalUnit]");
                else if (abh.EndsWith("0000"))
                    strSql.Append("and left(abh,2)='" + abh.Substring(0, 2) + "' group by hname,[Stage],[totalUnit]");
                else if (abh.EndsWith("00"))
                    strSql.Append("and left(abh,4)='" + abh.Substring(0, 4) + "'group by hname,[Stage],[totalUnit]");
                else
                    strSql.Append("and abh='" + abh + "'group by hname,[Stage],[totalUnit]");
            }
            else
            {
                strSql.Append("and abh='" + abh + "'group by hname,[Stage],[totalUnit]");
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


        public DataSet GetListc(string abh,string harm,string stime,string etime,string ptype,string mlevel)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select hname,SUM(cast(femaleNums as int)) as females,SUM(cast(maleNums as int)) as males,SUM(cast(totalCount as int)) as counts from Vforestpets where 1=1");
            if (harm != "")
                strSql.AppendFormat(" and hname='{0}'", harm);
            if(stime!="")
                strSql.AppendFormat(" and inputTime>='{0}'", stime);
            if (etime != "")
                strSql.AppendFormat(" and inputTime<='{0}'", etime);
            if (ptype != "")
            {
                strSql.AppendFormat(" and ptype='{0}'", ptype);

            }
            if (mlevel != "" && mlevel!="4,3,2,1")
                strSql.AppendFormat(" and mlevel in ({0})", mlevel);
            if (abh.Length == 6)
            {
                if (abh.EndsWith("000000"))
                    strSql.Append(" group by hname");
                else if (abh.EndsWith("0000"))
                    strSql.Append("and left(abh,2)='"+abh.Substring(0,2)+"' group by hname");
                else if (abh.EndsWith("00"))
                    strSql.Append("and left(abh,4)='" + abh.Substring(0, 4) + "'group by hname");
                else
                    strSql.Append("and abh='" + abh + "'group by hname");
            }
            else
            {
                strSql.Append("and abh='" + abh + "'group by hname");
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "ForestPets";
			parameters[1].Value = "fp_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

